/*
 * Serum
 *
 * @license      GNU Lesser General Public Licence see LICENCE-LGPL file or http://www.gnu.org/licenses/lgpl.html
 */

Serum.Module.Base = Ext.extend(Serum.Module.Abstract, {

    constructor: function() {
        Serum.Module.Base.superclass.constructor.call(this);
    },

    formClass: function() {
		switch (Serum.Selector.get().action) {
			case 'advancedSearch':
                // Search form
                return 'Serum.Form.Module.Search';
            default:
                // Default form
                return 'Serum.Form.Module.Edit';
		}
    },

    listClass: function() {
        return 'Serum.Grid.Module.List';
    },

    processElement: function(listeId, action) {
        Serum.Ajax.request({
            scope:      this,
            params:     {
                            method:         Serum.Selector.get().method({ module: Serum.Selector.get().module, controller: 'Index', action: action }),
                            requestId:      Serum.Helper.Request.id(),
                            listeId:        listeId
                        },
            onSuccess:  this.onProcessSuccess,
            onFailure:  this.onProcessError
        });
    },

    enableElement: function(listeId) {
        this.processElement(listeId, 'enable');
    },

    disableElement: function(listeId) {
        this.processElement(listeId, 'disable');
    },

    deleteElement: function(listeId) {
        this.processElement(listeId, 'moveTrash');
    },

    enableAdjacentElement: function(listeId) {
        this.processElement(listeId, 'enableAdjacent');
    },

    disableAdjacentElement: function(listeId) {
        this.processElement(listeId, 'disableAdjacent');
    },

    deleteAdjacentElement: function(listeId) {
        this.processElement(listeId, 'moveTrashAdjacent');
    },

    enableParentElement: function(listeId) {
        this.processElement(listeId, 'enableParent');
    },

    disableParentElement: function(listeId) {
        this.processElement(listeId, 'disableParent');
    },

    deleteParentElement: function(listeId) {
        this.processElement(listeId, 'moveTrashParent');
    },

    onProcessSuccess: function(result) {
        Serum.Selector.get().set({ action: 'index' }, false);
    },

    onProcessError: function(result) {
        // console.log('Ce bug est dû à Hervé, veuillez lui casser les dents');
    }
});